#include <ros/ros.h>
#include <std_msgs/Bool.h>
#include <iostream>
#include <ros/service_server.h>
#include <actionlib/server/simple_action_server.h>
#include "../include/rerun_move_base/reRunAction.h"



using namespace std;

typedef actionlib::SimpleActionServer<rerun_move_base::reRunAction> reRun_action_server;
reRun_action_server *reRun_srv;

void reRun_ac_cb(const rerun_move_base::reRunGoalConstPtr& goal)
{

    ROS_INFO("request for rerun recieved!");
    if(goal->rerun)
    {
        system("rosnode kill /move_base");
        sleep(2);
        system("roslaunch robina_2dnav rerun_move_base.launch");
        reRun_srv->setSucceeded();
    }
    else
        reRun_srv->setAborted();

}

int main(int argc,char **argv)
{
  ros::init(argc,argv,"run_move_base");
  ros::NodeHandle n;

  reRun_srv = new reRun_action_server(n, "reRun_move_base",reRun_ac_cb, false);
  reRun_srv->start();

  ros::Rate loop_rate(10);

  while(ros::ok())
  {

    ros::spinOnce();
    loop_rate.sleep();
  }

  return 0;
}
